package com.zhudeshuai.zhudemolist.animation;

import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.zhudeshuai.zhudemolist.R;

/**
 *
 * @author zhudeshuai
 * @since 16/8/13
 */
public class ValueAnimatorDemo extends Activity {


    private ImageView mIconIv;
    private Button mTranslateBt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_value_animator_demo);

        mIconIv = (ImageView) findViewById(R.id.iv_icon);
        mTranslateBt = (Button) findViewById(R.id.bt_translate);
        mTranslateBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                translate();
            }
        });

    }


    private void translate(){
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(1,400);
        valueAnimator.setDuration(500);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                mIconIv.setTranslationX(value);
                mIconIv.setTranslationY(value*2);
            }
        });
        valueAnimator.start();
    }
}
